package td;

import ui.GhostView;

public class Ghost extends Enemy {
	public Ghost(Field position, DoTListener listener) {
		super(position, listener);
		this.hp = 20;
		this.speed = 1;
		this.value = 5;
		this.damage = 5;
		this.viewable = new GhostView(this);
	}

	public void step() {
		/* Asks the field to get one of its steppable neighbours */
		Field newField = position.getSteppable();
		/* Adds the ghost to that next field, and removes from current */
		newField.addElement(this);
		position.removeElement(this);
		position = newField;

		/*If the new field is the endpoint, the player loses hp*/
		if (position.isEndPoint) {
			listener.enemyWon(this);
			position.removeElement(this);
		}
	}

	/*
	 * Method to create two small enemies when a CutterBullet 
	 * hits and splits it in half.
	 */
	public void cutInHalf() {
		Ghost smallGhost1 = new Ghost(position, listener);
		Ghost smallGhost2 = new Ghost(position, listener);
		smallGhost1.hp = this.hp / 2;
		smallGhost2.hp = this.hp / 2;
		smallGhost1.viewable.update();
		smallGhost2.viewable.update();
		position.removeElement(this);
		position.addElement(smallGhost1);
		position.addElement(smallGhost2);
		listener.cutInHalf(this,smallGhost1,smallGhost2);
	}
}
